﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Manager;
using Model;
using ExtAspNet;
using Manager.CustomerHelper;
namespace HealthSystem
{
    public partial class School_Edit : BasePage
    {
        HW_SchoolManager manager = new HW_SchoolManager();
        public override ModuleType Module
        {
            get
            {
                return ModuleType.SchoolManager;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                orgname.OnClientTriggerClick = Window1.GetSaveStateReference(orgid.ClientID, orgname.ClientID)
                   + Window1.GetShowReference("./ChooseOrg.aspx", "选择体检机构");
                btnClose.OnClientClick = ActiveWindow.GetConfirmHidePostBackReference();
                string id = Request["id"].ToString();
                HW_School school = manager.GetById(id);
                //bool exist = DistrictCache.CheckExist(CustomerProfile.DistrictId, school.DistrictCode);
                //if (exist)
                //{
                    Bind(school);
                //}
            }
        }
        public void Bind(HW_School school)
        {
            this.name.Text = school.Name;
            this.id.Text = school.SchoollCode;

            LinkMan.Text = school.LinkMan;
            MobilePhone.Text=school.MobilePhone;
            OfficePhone.Text = school.OfficePhone;
            Address.Text = school.Address;
            SchoolType.Text = school.SchoolType;
            Email.Text = school.Email;
            manager.ModHW_School(school);
            if (!string.IsNullOrEmpty(school.OrgCode))
            {
                HW_OrgManager orgManager = new HW_OrgManager();
                HW_Org org = orgManager.GetById(school.OrgCode);
                orgname.Text = org.OrgName;
            }
            orgid.Text = school.OrgCode;
        }
        protected void Save_Click(object sender, EventArgs e)
        {
            string id = Request["id"].ToString();
            HW_School school = manager.GetById(id);
            bool exist = DistrictCache.CheckExist(CustomerProfile.DistrictId, school.DistrictCode);
            if (exist)
            {
                school.Name = this.name.Text;
                school.LinkMan = LinkMan.Text;
                school.MobilePhone = MobilePhone.Text;
                school.OfficePhone = OfficePhone.Text;
                school.Address = Address.Text;
                school.SchoolType = SchoolType.Text;
                school.Email = Email.Text;
                school.OrgCode = orgid.Text;
                manager.ModHW_School(school);

                //school.Name = this.name.Text;
                //school.LinkMan = LinkMan.Text;
                //school.MobilePhone = MobilePhone.Text;
                //school.OfficePhone = OfficePhone.Text;
                //school.Address = Address.Text;
                //school.SchoolType = SchoolType.Text;
                //school.Email = Email.Text;
                //manager.ModHW_School(school);
                PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
            }
            else
            {
                Alert.Show("您没有权限修改该学校");
            }
        }
    }
}